<?php
/**
 * $Id: hooks.php 7 2009-01-05 19:33:38Z gpo_gigapromoters $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * @version 			$Rev: 7 $
 * @lastModifiedBy		$LastChangedBy: gpo_gigapromoters $
 * @lastChanged			$Date: 2009-01-06 01:03:38 +0530 (Tue, 06 Jan 2009) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */
 
 function languagesAfterComponentInitHook($controller)
 {
 	if(!cr('Language.active'))
	{
		return;
	}	 
 	if(extension_loaded('mbstring') == false)
 	{
 		$controller->log('mbstring extension not loaded multi lingual functionality might not work as expected.',LOG_WARNING);
 	}
	 if(cr('Language.active') == 1 && cr("cmsInstalled"))
	 {
		 
	 	if($controller->Session->read("Config.language") && !cr("Language.userLanguage") && cr("Langugae.allow_user_language"))
		{
			if($controller->params['url']['url'] == "/")
			{
				$controller->redirect("/".$controller->Session->read("Config.language"));
			}
		}
	 	cri('Languages.Language')->setLanguageConfiguration();
		if(cr("Language.userLanguage"))
		{
			$controller->Session->write("Config.language",cr("Language.userLanguage"));
		}
	 }
 } 
 
 function languagesafterFilterHook($ctrl)
 {
 	if(cr('Language.active') && !defined('CAKEPHP_SHELL') && !isset($ctrl->params['requested']) && headers_sent() === false)	
 	{
 		//$ctrl->header("Content-Type: text/html; charset=utf-8");
 		$ctrl->header("Content-Language:".cr('Config.language'));
 	}
 }

 function languagesBuildAdminMenuHook($backend)
 {
 	if(cr('Language.active'))
 	{
 		$backend->addMenuItem(ADMIN_MISC, __('Languages'),'/languages/index');
	}
	
 }
 
 function languagesbeforeFilterHook($controller)
 {
 	$sessionLanguage = @$controller->Session->read("Config.language");
 	if(!$sessionLanguage && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
 	{
 		$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
 		if(cri('Languages.Language')->isActiveLanguage($lang))
 		{
 			$controller->Session->write("Config.language", $lang);
 		}
 	}
 }
 
 ?>